Global Operations

global operations

P4 supports a number of operations for dealing with all processes at once.

p4_broadcastx
\begin{example}
p4_broadcastx(type, data, data_len, data_type)
int type;
char *data;
int data_len, data_type;
\end{example}

p4_broadcast
\begin{example}
p4_broadcast(type, data, data_len)
int type;
char *data;
int data_len;
\end{example}
provide the ability to broadcast messages like p4_send and p4_sendx.

p4_global_op
\begin{example}
p4_global_op(type,x,nelem,size,op,data_type)
int type;
char *x;
int size, nelem;
int (*op)();
int data_type;
\end{example}
where op is one of:
\begin{example}
p4_int_absmax_op()
p4_int_absmin_op()
p4_int_max_op()
p4_int_min...
...)
p4_flt_max_op()
p4_flt_min_op()
p4_flt_mult_op()
p4_flt_sum_op()
\end{example}

and data_type is one of P4INT, P4LNG, P4FLT, or P4DBL.

This collection of routines provide the ability to do a variety of global operations. See the example programs in subdirectory p4/contrib. They apply the commutative operation op globally to x on an element-by-element basis and broadcast the result to all nodes. That is each process ends up with


\begin{example}
for (i=0; i<n; i++)
x[i] = x[node 0][i] op x[node 1][i] op x[node 2][i] op ...
\end{example}
op should be of the form


\begin{example}
VOID op(char *x, char *y, int nelem)
\{
data_type *a = (data_...
...= (data_type *) y;
\par
while (nelem--)
*a++ operation= *b++;
\}
\end{example}
where data_type and operation are chosen appropriately.

The order in which nodes apply the operation is undefined (hence op must be commutative). The communication may be internally sub-blocked so the function op should not be hardwired to specific vector lengths.

This is still a relatively primitive version, which gathers the necessary data up a balanced binary tree and then uses p4_broadcast to send the results back.

barrier p4_global_barrier
\begin{example}
VOID p4_global_barrier(type)
int type;
\end{example}
This procedure takes one argument which is the message type to be used for internal message-passing. It causes the invoking process to hang until all processes specified in the procgroup file have invoked the procedure.

Functions for Shared Memory,Functions for Timing p4 Programs,Functions for Message Passing,Top